package com.exigen.perflabstat.dao.jpa;

import java.util.List;

import javax.persistence.Query;

import com.exigen.perflabstat.base.GenericJPADAO;
import com.exigen.perflabstat.dao.TestSummaryDataDao;
import com.exigen.perflabstat.models.TestSummaryData;


public class TestSummaryDataJpaDao extends GenericJPADAO<TestSummaryData, Long> implements TestSummaryDataDao  {
	
	public TestSummaryDataJpaDao() {
		super(TestSummaryData.class);
	}

	@SuppressWarnings("unchecked")
	public List<TestSummaryData> allTestSummaryDatas() {
		
		Query query = getEntityManager().createQuery("from TestSummaryData");
		
		List<TestSummaryData> result = query.getResultList();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public TestSummaryData checkIfExists(TestSummaryData testSummaryData) {
		TestSummaryData test;
		
		Query query = getEntityManager().createQuery("select tsd from TestSummaryData tsd where tsd.TESTSUMMARY_ID = :testSummaryId");
		query.setParameter("testSummaryId", testSummaryData.getTESTSUMMARY_ID());
		query.setMaxResults(1);
		
		List<TestSummaryData> result = query.getResultList();
		
		if(result.isEmpty())return null;
		
		test = result.get(0);
		
		return test;
	}

}